package com.yjha.huazhubusiness.config;


// import com.yjha.huazhubusiness.interceptor.LoginInterceptor;
// import com.yjha.huazhubusiness.utils.FileUploadUtil;
import com.yjha.huazhubusiness.interceptor.LoginInterceptor;
import com.yjha.huazhubusiness.utils.MultipartJackson2HttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class MyMvcConfigurer implements WebMvcConfigurer {
    // @Resource
    // private FileUploadUtil fileUploadUtil;

    @Resource
    private LoginInterceptor loginInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册⾃定义拦截器对象
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns( // 排除不需要拦截的路径
                        "/login",          // 登录页面
                        "/static/**",     // 静态资源
                        "/public/**",     // 公共资源
                        "/error",         // 错误页面
                        "/wx/**"
                );

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // registry.addResourceHandler("/upload/**").addResourceLocations("file:"+ fileUploadUtil.getWinOrLinuxUploadFilePath());
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/template/model/");
    }
    //配置swagger
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.add(new MultipartJackson2HttpMessageConverter());
    }
}
